{% extends "personal_center/base.html" %}

{% block page_link %}
    {#    <script src="../../static/administrative/js/car_apply_detail.js"></script>#}
    <link rel="stylesheet" href="../../static/technological/css/style.css">

{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }

        .add_background {
            background: #A9A9A9;
        }

        .input-style {
            display: inline-block;
            width: 100%;
            height: 35px;
            font-size: 14px;
            border: none;
            background: white;
        }

        tr {
            height: 35px;
        }

        td {
            padding-right: 5px;
            outline: none;
            height: 40px;
        }

        th {
            text-align: center;
        }

        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }

        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }

        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div class="headline">
        <div style="width: 15%;height: 100%;line-height: 40px;float: left;padding-left: 1%;">
            <a href="#" style="color: #0b0b0b;">
                <i class="iconfont icon-faqi"></i>
                <a href="/finance/new_medical_services_list_view" style="color: #0b0b0b;">新增医疗服务项目审批</a>
            </a>
        </div>
        <div style="height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"
                    onclick="save_data()">
                保存
            </button>
        </div>

        <div style="width: 15%;height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"
                    onclick="submit_data()">
                提交
            </button>
        </div>
    </div>
    <hr>

    <div style="width: 100%;height: 95%;overflow: auto;">
        <div id="menu_from"
             style="width: 100%;height: 100%;color: #2C3E50;display: inline-block;vertical-align: top;background: white;">
            <div style="width: 100%;height: 90%;display: inline-block;vertical-align: center;">

                <div style="width: 95%;margin-left: 2.5%;margin-top: 1%;height: 40px;padding-left: 0.5%;line-height: 40px;background: white;border: #cfcfcf solid 1px;text-align: center;">
                    <h3 id="form_name" style="letter-spacing: 8px;">新增医疗服务项目审批</h3>
                </div>
                <div style="width: 95%;margin-left: 2.5%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #dfdfdf;border: #cfcfcf solid 1px;">
                    基本信息
                </div>

                <div style="width: 95%;margin-left: 2.5%;">
                    <table style="width: 100%;">
                        <tr style="margin-left: 1%;">
                            <td style="width: 8%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                申请人
                            </td>
                            <td id="applicat"
                                style="width: 30%;height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;">{{ realname }}</td>

                            <td style="width: 8%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                申请部门
                            </td>
                            <td id="department"
                                style="width: 30%;border: #cfcfcf solid 0.5px;padding-left: 1%;line-height: 35px;">{{ department }}</td>
                        </tr>

                    </table>
                </div>

                <div style="width: 95%;margin-left: 2.5%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #dfdfdf;">
                    申请详情
                </div>

                <div style="width: 95%;margin-left: 2.5%;;">
                    <table style="width: 100%;">
                        <tr style="margin-left: 1%;">
                            <td style="width: 8%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                项目名称
                            </td>
                            <td id="title"
                                style="width: 30%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;"
                                contenteditable="true">{{ obj.title }}</td>

                            <td style="width: 8%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                项目编号
                            </td>
                            <td id="number"
                                style="width: 30%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;"
                                contenteditable="true">{{ obj.number }}</td>
                        </tr>
                    </table>
                    <table style="width: 100%;">

                        <tr style="margin-left: 1%;">

                            <td style="width: 8%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: right;">
                                项目分类
                            </td>
                            <td id="type"
                                style="width: 30%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;"
                                contenteditable="true">
                                <select name="" id="yc_type" style="width: 100%;height: 100%;border: none; "
                                        onchange="change_type()">
                                    <option value="one" {% if obj.type == 'one' %}
                                            selected="selected" {% endif %}>综合医疗服务类
                                    </option>
                                    <option value="two" {% if obj.type == 'two' %}
                                            selected="selected" {% endif %}>医技诊疗类
                                    </option>
                                    <option value="three" {% if obj.type == 'three' %}
                                            selected="selected" {% endif %}>临床诊疗类
                                    </option>
                                </select>
                            </td>
                            <td style="width: 8%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-top: none;">
                                项目类别
                            </td>
                            <td id="category" style="width: 30%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-top: none;"
                                contenteditable="true">
                                <select name="" id="one_type" style="width: 100%;height: 100%;border: none; ">
                                    <option value="a" {% if obj.category == 'a' %}
                                            selected="selected" {% endif %}>一般医疗服务
                                    </option>
                                    <option value="b" {% if obj.category == 'b' %}
                                            selected="selected" {% endif %}>一般检查治疗
                                    </option>
                                    <option value="c" {% if obj.category == 'c' %}
                                            selected="selected" {% endif %}>预防保健及其他
                                    </option>
                                    <option value="d" {% if obj.category == 'd' %}
                                            selected="selected" {% endif %}>其他医疗服务项目
                                    </option>
                                </select>
                                <select name="" id="two_type"
                                        style="width: 100%;height: 100%;border: none; display: none">
                                    <option value="e" {% if obj.category == 'e' %}
                                            selected="selected" {% endif %}>医学影像
                                    </option>
                                    <option value="f" {% if obj.category == 'f' %}
                                            selected="selected" {% endif %}>超声检查
                                    </option>
                                    <option value="g" {% if obj.category == 'g' %}
                                            selected="selected" {% endif %}>核医学
                                    </option>
                                    <option value="h" {% if obj.category == 'h' %}
                                            selected="selected" {% endif %}>放射治疗
                                    </option>
                                    <option value="i" {% if obj.category == 'i' %}
                                            selected="selected" {% endif %}>检验
                                    </option>
                                    <option value="j" {% if obj.category == 'j' %}
                                            selected="selected" {% endif %}>血型与配血
                                    </option>
                                    <option value="k" {% if obj.category == 'k' %}
                                            selected="selected" {% endif %}>病理检查
                                    </option>
                                </select>
                                <select name="" id="three_type"
                                        style="width: 100%;height: 100%;border: none; display: none">
                                    <option value="m" {% if obj.category == 'm' %}
                                            selected="selected" {% endif %}>临床各种系统诊疗
                                    </option>
                                    <option value="l" {% if obj.category == 'l' %}
                                            selected="selected" {% endif %}>经血管介入治疗
                                    </option>
                                    <option value="n" {% if obj.category == 'n' %}
                                            selected="selected" {% endif %}>手术治疗
                                    </option>
                                    <option value="o" {% if obj.category == 'o' %}
                                            selected="selected" {% endif %}>物理治疗与康复
                                    </option>
                                    <option value="p" {% if obj.category == 'p' %}
                                            selected="selected" {% endif %}>中医及民族医诊疗类
                                    </option>
                                </select>
                            </td>
                        </tr>
                    </table>

                    <table style="width: 100%;">
                        <tr style="margin-left: 1%;">
                            <td style="width: 8%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-top: none;">
                                申请理由
                            </td>
                            <td id="reason"
                                style="width: 68%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-top: none;"
                                contenteditable="true">{{ obj.reason }}</td>
                        </tr>
                    </table>
                    <table style="width: 100%;">
                        <tr style="margin-left: 1%;">
                            <td style="width: 8%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-top: none;">
                                项目内涵
                            </td>
                            <td id="connotation"
                                style="width: 68%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-top: none;"
                                contenteditable="true">{{ obj.connotation }}</td>
                        </tr>
                    </table>
                    <table style="width: 100%;">
                        <tr style="margin-left: 1%;">
                            <td style="width: 8%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-top: none;">
                                其&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;他
                            </td>
                            <td id="note"
                                style="width: 68%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-top: none;"
                                contenteditable="true">{{ obj.note }}</td>
                        </tr>
                    </table>
                </div>

                <div style="width: 95%;margin-left: 2.5%;">
                    <div style="width: 100%;height: 40px;line-height: 40px;background-color: #dfdfdf;color: #1E90FF;padding-left: 1%;border: #cccccc solid 1px;border-top: none;border-bottom: none;padding-right: 1%;">
                        上传附件
                        <a href="javascript:;" class="file" style="vertical-align: top;margin-top: 5px;float: right;">
                            上传文件
                            <input type="file" name="party_main_body" id="party_main_body"
                                   onchange="upload_accessory('file1', 'party_main', 'party_main_body')">
                        </a>
                    </div>
                    <table style="width: 100%;">
                        <thead>
                        <tr>
                            <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">序号</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件名称
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件大小
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传时间
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传人员
                            </td>
                            <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">操作
                            </td>
                        </tr>
                        </thead>
                        <tbody style="overflow: auto;" id="party_main">
                        {% for record in file_list %}
                            <tr>
                                <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">{{ forloop.counter }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.file_name }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.file_size }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.upload_time }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.uploader }}</td>
                                <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                    <a target='_blank' href="{{ record.file_path }}">查看</a> | <a style="color: red;"
                                                                                                 href='#'
                                                                                                 onclick='RemoveTr(this, "party_main", {{ record.id }})'>删除</a>
                                </td>
                            </tr>
                        {% endfor %}

                        </tbody>
                    </table>
                </div>
            </div>

        </div>

    </div>


{% endblock %}

{% block script %}
    <script type="text/javascript" src="../../static/public_file/other/jquery.js"></script>
    <script src="../../static/administrative/layDate-v5.0.9/laydate/laydate.js"></script> <!-- 改成你的路径 -->

    <script type="text/javascript">
        window.onload = function () {
            document.getElementById("sponsor").className = "add_class";
            document.getElementById("personage").className = "add-nav-active";
            var yc_type = '{{ obj.type }}'
            if (yc_type === 'one') {
                $("#one_type").css("display", "block");
                $("#two_type").css("display", "none");
                $("#three_type").css("display", "none");
            } else if (yc_type === 'two') {
                $("#one_type").css("display", "none");
                $("#two_type").css("display", "block");
                $("#three_type").css("display", "none");
            } else {
                $("#one_type").css("display", "none");
                $("#two_type").css("display", "none");
                $("#three_type").css("display", "block");
            }
        };
        lay('#version').html('-v' + laydate.v);


        const uuid = '{{ obj.fj_number }}'

        // 上传附件
        function upload_accessory(file_type, tbody_id, accessory_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            var files = document.getElementById(accessory_type).files[0];
            form.append(file_type, files);
            form.append('number', uuid)
            form.append('source', 'xzylfw')
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, tbody_id)
                    }
                }
            };
        }

        function change_type() {
            var yc_type = $("#yc_type ").val();
            if (yc_type === 'one') {
                $("#one_type").css("display", "block");
                $("#two_type").css("display", "none");
                $("#three_type").css("display", "none");
            } else if (yc_type === 'two') {
                $("#one_type").css("display", "none");
                $("#two_type").css("display", "block");
                $("#three_type").css("display", "none");
            } else {
                $("#one_type").css("display", "none");
                $("#two_type").css("display", "none");
                $("#three_type").css("display", "block");
            }

        }

        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])) {
                for (var i = 0; i < JsonData["pdf_path"].length; i++) {
                    var tr = document.createElement("tr");
                    var td1 = document.createElement("td");
                    var td2 = document.createElement("td");
                    var td3 = document.createElement("td");
                    var td4 = document.createElement("td");
                    var td5 = document.createElement("td");
                    var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length + 1;
                    td1.style.textAlign = "center";
                    td1.style.border = "#cccccc solid 1px";
                    td1.style.borderTop = "none";
                    td2.innerHTML = JsonData["file_name"];
                    td2.style.paddingLeft = "1%";
                    td2.style.border = "#cccccc solid 1px";
                    td2.style.borderLeft = "none";
                    td2.style.borderTop = "none";
                    td3.innerHTML = JsonData["file_size"];
                    td3.style.textAlign = "center";
                    td3.style.border = "#cccccc solid 1px";
                    td3.style.borderLeft = "none";
                    td3.style.borderTop = "none";
                    td4.innerHTML = JsonData["upload_time"];
                    td4.style.textAlign = "center";
                    td4.style.border = "#cccccc solid 1px";
                    td4.style.borderLeft = "none";
                    td4.style.borderTop = "none";
                    td5.innerHTML = JsonData["uploader"];
                    td5.style.textAlign = "center";
                    td5.style.border = "#cccccc solid 1px";
                    td5.style.borderLeft = "none";
                    td5.style.borderTop = "none";
                    td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["pdf_path"][i]["id"] + "\")'>删除</a>";
                    td6.style.textAlign = "center";
                    td6.style.border = "#cccccc solid 1px";
                    td6.style.borderLeft = "none";
                    td6.style.borderTop = "none";
                    tr.appendChild(td1);
                    tr.appendChild(td2);
                    tr.appendChild(td3);
                    tr.appendChild(td4);
                    tr.appendChild(td5);
                    tr.appendChild(td6);
                    t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1) {
                    document.getElementById("del_adjunct").style.display = 'block';
                }
            } else {
                var tr = document.createElement("tr");
                var td1 = document.createElement("td");
                var td2 = document.createElement("td");
                var td3 = document.createElement("td");
                var td4 = document.createElement("td");
                var td5 = document.createElement("td");
                var td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length + 1;
                td1.style.textAlign = "center";
                td1.style.border = "#cccccc solid 1px";
                td1.style.borderTop = "none";
                td2.innerHTML = JsonData["file_name"];
                td2.style.paddingLeft = "1%";
                td2.style.border = "#cccccc solid 1px";
                td2.style.borderLeft = "none";
                td2.style.borderTop = "none";
                td3.innerHTML = JsonData["file_size"];
                td3.style.textAlign = "center";
                td3.style.border = "#cccccc solid 1px";
                td3.style.borderLeft = "none";
                td3.style.borderTop = "none";
                td4.innerHTML = JsonData["upload_time"];
                td4.style.textAlign = "center";
                td4.style.border = "#cccccc solid 1px";
                td4.style.borderLeft = "none";
                td4.style.borderTop = "none";
                td5.innerHTML = JsonData["uploader"];
                td5.style.textAlign = "center";
                td5.style.border = "#cccccc solid 1px";
                td5.style.borderLeft = "none";
                td5.style.borderTop = "none";
                td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["id"] + "\")'>删除</a>";
                td6.style.textAlign = "center";
                td6.style.border = "#cccccc solid 1px";
                td6.style.borderLeft = "none";
                td6.style.borderTop = "none";
                tr.appendChild(td1);
                tr.appendChild(td2);
                tr.appendChild(td3);
                tr.appendChild(td4);
                tr.appendChild(td5);
                tr.appendChild(td6);
                t_table.appendChild(tr);
            }
        }

        function RemoveTr(_this, tbody_id, wj_id) {
            var table = document.getElementById(tbody_id);
            var trNode = $(_this).parent().parent();
            trNode.remove();

            for (var i = 0; i < table.children.length; i++) {
                table.children[i].children[0].innerHTML = i + 1;
            }

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/delete_attachments_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id=" + String(wj_id));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        alert("删除成功！")
                    }
                }
            };
        }

        function submit_data() {
            var title = document.getElementById('title').innerText;
            var number = document.getElementById('number').innerText;
            var reason = document.getElementById('reason').innerText;
            var connotation = document.getElementById('connotation').innerText;
            var note = document.getElementById('note').innerText;
            var type = $("#yc_type").val();
            if (type === 'one') {
                var category = $("#one_type").val();
            } else if (type === 'two') {
                category = $("#two_type").val();
            } else {
                category = $("#three_type").val();
            }
            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/finance/new_medical_services_index_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("type=" + String(type) + "&id=" + String({{obj.id}}) + "&title=" + String(title) + "&number=" + String(number) + "&reason=" + String(reason) + "&connotation=" + String(connotation) + "&note=" + String(note) + "&category=" + String(category));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("提交成功");
                            window.location = "/finance/new_medical_services_list_view";
                            document.getElementById("loading").style.display = "none";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
            };

        }

        function save_data() {
            var title = document.getElementById('title').innerText;
            var number = document.getElementById('number').innerText;
            var reason = document.getElementById('reason').innerText;
            var connotation = document.getElementById('connotation').innerText;
            var note = document.getElementById('note').innerText;
            var type = $("#yc_type").val();
            if (type === 'one') {
                var category = $("#one_type").val();
            } else if (type === 'two') {
                category = $("#two_type").val();
            } else {
                category = $("#three_type").val();
            }
            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/finance/new_medical_services_draft_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("type=" + String(type) + "&id=" + String({{obj.id}}) + "&title=" + String(title) + "&number=" + String(number) + "&reason=" + String(reason) + "&connotation=" + String(connotation) + "&note=" + String(note) + "&category=" + String(category));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("提交成功");
                            window.location = "/finance/new_medical_services_list_view";
                            document.getElementById("loading").style.display = "none";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
            };

        }

    </script>
{% endblock %}



